//
//  YYStatus.swift
//  YYWeibo
//
//  Created by strongwallyi on 16/1/2.
//  Copyright © 2016年 strongwallyi. All rights reserved.
//  微博的模型

import UIKit

class YYStatus: NSObject {
    //当前微博的 id
    var id: Int64 = 0

    //微博的内容
    var text: String?
    
    //微博的创建时间
    var created_at: String?
    
    //微博的来源
    var source: String?
    
    //当前微博的作者
    var user: YYUser?
    
    //转发微博的字段
    var retweeted_status: YYStatus?
    
    //转发评论赞的数量
    var reposts_count: Int = 0
    var comments_count: Int = 0
    var attitudes_count: Int = 0
    
    //配图视图需要的数据
    var pic_urls: [YYStatusPictureInfo]?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            
            if let dict = value as? [String: AnyObject]{
                
                //字典转模型
                user = YYUser(dict: dict)
            }
        }else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject]{
                
                retweeted_status = YYStatus(dict: dict)
            }
        }else if key == "pic_urls" {
            if let dicts = value as? [[String: AnyObject]]{
                pic_urls = [YYStatusPictureInfo]()
                //遍历字典转模型
                for dict in dicts{
                    let pictureInfo = YYStatusPictureInfo(dict: dict)
                    pic_urls?.append(pictureInfo)
                }
            }
        }else{
            //再次一定要调用super,因为 super 才是真正的赋值
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String{
        let keys = ["pic_urls"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
